package chapter3;

import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author lzy
 * @create 2019-03-20 下午2:23
 */
public class InitialTest {
    public static void main(String[] args) {
        System.out.println("直接访问全局常量");
        System.out.println(IniDemo.CONSTANT);
        System.out.println("------------------");

        System.out.println("访问静态常量");
        System.out.println(IniDemo.anInt);
        System.out.println(IniDemo.anInt2);
        System.out.println("------------------");

        System.out.println("初始化对象");
        IniDemo demo = new IniDemo();
        System.out.println(demo.value);
        System.out.println(IniDemo.anInt);
    }
}

class IniDemo {
    public static final String CONSTANT = "constant";
    public static int anInt;
    public static Date date;
    public static int anInt2 = 12;

    static {
        System.out.println("执行静态块");
        anInt2 = 23;
        date = new Date();
    }

    public String string;
    public double value;

    {
        System.out.println("执行构造块");
        this.value = 3.14;
    }

    public IniDemo() {
        System.out.println("构造方法");
        anInt = 123;
        string = "string";
    }
}
